package com.youi.service.impl;

import com.google.common.collect.Maps;
import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.UserorderexcelVoDao;
import com.youi.entity.Yibaopayment;
import com.youi.entity.vo.UserorderexcelVo;
import com.youi.service.GoodtypeService;
import com.youi.service.UserorderexcelVoService;
import com.youi.service.YibaopaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class UserorderexcelVoServiceImpl implements UserorderexcelVoService {

    @Resource
    private UserorderexcelVoDao userorderexcelVoDao;

    @Autowired
    private YibaopaymentService yibaopaymentService;

    @Autowired
    private GoodtypeService goodtypeService;

    @Override
    public List<UserorderexcelVo> getUserorderexcelList(Long merchantId, Integer status, String orderNos, String pms, String merchantName, String goodsNo,
                                                        String otherParams, String start, String end) {
        return userorderexcelVoDao.getUserorderexcelList(merchantId, status, orderNos, pms, merchantName, goodsNo, otherParams, start, end);
    }

    @Override
    public void getTopOrderNo(List<UserorderexcelVo> userorderexcelList) {
        if (userorderexcelList != null && !userorderexcelList.isEmpty()) {
            for (UserorderexcelVo userorderexcel : userorderexcelList) {
                Map<String, Object> params = Maps.newHashMap();
                params.put(Common.DELSTATUS, DelStatus.NODEL);
                Map<String, Object> searchParams = Maps.newHashMap();
                searchParams.put("orderNos", userorderexcel.getOrderNo());
                Yibaopayment yibaopayment = yibaopaymentService.getByParam(params, searchParams, null);
                if (yibaopayment != null) {
                    userorderexcel.setTopOrderNo(yibaopayment.getSerialNumber());
                }
            }
        }
    }


}